package spring_ioc.hello1;

import spring_ioc.hello1.service.Action;
import spring_ioc.hello1.service.ExecuteAction;
import spring_ioc.hello1.service.LowerAction;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

//import org.springframework.context.support.ClassPathXmlApplicationContext;

@RunWith(SpringRunner.class)
@ContextConfiguration(locations={"file:.../applicationContext.xml"})
public class Test2_InJunit {

	@Test
	public void test1() {
		String XML = "src/main/java/spring_ioc/hello1/applicationContext.xml";
		ApplicationContext ctx = new
				FileSystemXmlApplicationContext(XML);

		Action action = (Action) ctx.getBean("TheAction1");

		action.execute("Rod Johnson4");
	}

	@Autowired
	@Qualifier("TheAction1")
	Action action1;

	@Autowired
	@Qualifier("TheAction2")
	Action action2;

	@Test
	public void test2() {
		action1.execute("Rod Johnson5");
		action2.execute("Rod Johnson5");
	}
}
